function Rectangle(name, width, height) {
  this.name = name;
  this.width = width;
  this.height = height;
  this.area = function () {
    return this.width * this.height;
  };
}
const rect1 = new Rectangle("矩形 1", 20, 20);
const rect2 = new Rectangle("矩形 2", 30, 20);
console.log(rect1.name); // 输出：矩形 1
console.log(rect2.width); // 输出：30
console.log(rect1["width"]); // 输出：20
rect1.color = "红⾊";
console.log(rect1);
// 输出：Rectangle { name: '矩形 1', width: 20, height: 20, area: [Function], color: '红⾊' }
rect2.perimeter = function () {
  return 2 * (rect2.width + rect2.height);
};
console.log(rect2.perimeter()); // 输出：100
console.log(rect2);
// 输出：Rectangle { name: '矩形 2', width: 30, height: 20, area: [Function], perimeter: [Function] }
delete rect2.perimeter;
console.log(rect2);
// 输出：Rectangle { name: '矩形 2', width: 30, height: 20, area: [Function] }
console.log(rect1.hasOwnProperty("color")); // 输出：true
console.log(rect2.hasOwnProperty("color")); // 输出：false
console.log(rect1.hasOwnProperty("color")); // 输出：true
console.log(rect2.hasOwnProperty("color")); // 输出：false
console.log(Object.values(rect2));
// 输出：[ '矩形 2', 30, 20, [Function: area] ]
console.log(Object.entries(rect1));
// 输出：[['name', '矩形 1'], ['width', 20], ['height', 20],['area', [Function: area]], ['color', '红⾊']]
for (let [key, value] of Object.entries(rect1)) {
  console.log(`${key} - ${value}`);
}
// 输出：
// name - 矩形 1
// width - 20
// height - 20
// area - function () { return this.width * this.height; }
// color - 红⾊
for (let [key, value] of Object.entries(rect1)) {
  if (typeof value !== "function") {
    console.log(`${key} - ${value}`);
  }
}
// 输出：
// name - 矩形 1
// width - 20
// height - 20
// color - 红⾊